# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     interface_cases.py
    Description:   测试接口用例模型
 -------------------------------------------------
 """

from django.db import models

from apps.api_tests.models.interface import InterFace
from utils.models import CoreModel, table_prefix


# Create your models here.


# 接口用例管理模型
class InterFaceCase(CoreModel):
    """接口用例管理"""
    title = models.CharField(
        max_length=50,
        verbose_name='用例名称', help_text='用例名称', db_comment='用例名称'
    )
    interface = models.ForeignKey(
        to=InterFace, on_delete=models.CASCADE,
        verbose_name='接口', help_text='接口', db_comment='接口'
    )
    headers = models.JSONField(
        null=True, default=dict, blank=True,
        verbose_name='请求头配置', help_text='请求头', db_comment='请求头配置'
    )
    request = models.JSONField(
        null=True, blank=True, default=dict,
        verbose_name='请求参数配置', help_text='请求参数配置', db_comment='请求参数配置'
    )
    file = models.JSONField(
        null=True, default=list, blank=True,
        verbose_name='请求上传的文件参数', help_text='请求上传的文件参数', db_comment='请求上传的文件参数'
    )
    setup_script = models.TextField(
        null=True, blank=True, default='',
        verbose_name='前置脚本', help_text='前置脚本', db_comment='前置脚本'
    )
    teardown_script = models.TextField(
        null=True, blank=True, default='',
        verbose_name='后置脚本', help_text='后置脚本', db_comment='后置脚本'
    )

    def __str__(self):
        return self.title

    class Meta:
        db_table = table_prefix + 'interFaceCases'
        db_table_comment = '接口用例管理'

        verbose_name = "接口用例管理"
        verbose_name_plural = verbose_name
